package com.linkage.jz.bankruptcy.activity.Main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Person.PersonSettingReadMeActivity;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.bean.ProTalkReply;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;

import java.util.ArrayList;
import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import uk.co.senab.photoview.PhotoView;


/**
 * A login screen that offers login via email/password.
 */
public  class TempleyActivity extends BaseActivity implements OnClickListener{
    private static final String TAG = PersonSettingReadMeActivity.class.getSimpleName();

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {

        top_back.setOnClickListener(this);

    }

    @Override
    public void initTitle() {
        top_title = findViewById(R.id.top_title);
        bottom_tv = findViewById(R.id.bottom_tv);
        if(mType ==1) {
            bottom_tv.setText("请载明电话号码及法定代表人身份证号，以保障您有效加入项目");
            top_title.setText("法定代表人身份证明模板");
        }else{
            bottom_tv.setText("授权委托书必须载明电话号码，以便管理人验证身份");
            top_title.setText("授权委托书模板");
        }
        top_mune.setVisibility(View.INVISIBLE);

    }

    @Override
    public void initView() {

    }


    TextView top_title,bottom_tv;
    PhotoView image;
    Button top_back,top_mune;

    private static int  mType = 1;

    public static void start(Context context,int type) {
        mType = type;
        Intent intent = new Intent(context, TempleyActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_temple_file);

        initview();

        super.onCreate(savedInstanceState);
    }

    //初始化视图
    private void initview() {
        //登录层、下拉层、其它登录方式层



        top_back = findViewById(R.id.top_back);
        top_mune = findViewById(R.id.top_mune);


        image = findViewById(R.id.image);

        getTemp();
        setupViews();


    }


    private ViewGroup mMoreLayout;
    private List<ImageView> views = new ArrayList<ImageView>();
    private void setupViews() {
//        setContentView(R.layout.activity_main);

    }



    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.top_back:
                finish();
                break;

            case R.id.ll_lxcalc:
                RateCalcActivity.start(this);
                break;
            case R.id.ll_datecalc:
                DateCalcActivity.start(this);
                break;
            case R.id.ll_wyjcalc:
                PenaltyCalcActivity.start(this);
                break;
            case R.id.ll_carryout:
                CarryOutListActivity.start(this);
                break;
            default:
                break;
        }

//        final Object tag = v.getTag();      //通过之前setTag找到点击位置
//        if (tag != null) {
//            String department = (String) tag;
//            if("1".equalsIgnoreCase(department))
//            {
//                RateCalcActivity.start(this);
//            }else if("2".equalsIgnoreCase(department))
//            {
//                DateCalcActivity.start(this);
//            }else if("3".equalsIgnoreCase(department))
//            {
//                PenaltyCalcActivity.start(this);
//            }else if("4".equalsIgnoreCase(department))
//            {
////                ToolsActivity.start(getActivity());
//                CarryOutListActivity.start(this);
//            }
//        } // else ignored
    }


    private void getTemp() {

        Network
                .getAPIService()
                .getTemplate(getUserToken(),mType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }

                        String  data = json.get("data").getAsString();
//                       String data = "http://hk-ww1rsfanjian.oss-cn-hongkong.aliyuncs.com/c/d8/ba/65/c3d89b9ec0ba33fb3865454227c68822.jpg";
                        if (data != null) {

                            Glide.with(TempleyActivity.this).load(data)
                                    .placeholder(R.drawable.icon_stub)
                                    .into(image);
                        }
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                });
    }

}


